package defiant.common.tools;

import java.util.Enumeration;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;
import java.util.ResourceBundle;

public final class ResourceUtil {
	private ResourceUtil() {}
	
    public final static Properties loadProperties(final String name) {
//        return loadProperties (name,
//            Thread.currentThread ().getContextClassLoader ());
        //final ResourceBundle rb = ResourceBundle.getBundle(name, Locale.ENGLISH, Thread.currentThread().getContextClassLoader());
        final ResourceBundle rb = ResourceBundle.getBundle(name);
        final Properties props = new Properties();
        
        for (Enumeration<String> keys = rb.getKeys (); keys.hasMoreElements ();)
        {
            final String key = keys.nextElement ();
            final String value = rb.getString (key);
            
            props.put (key, value);
        } 
        
        return props;
    }
    
    public final static Map<String, String> loadMap(final String name) {
    	final ResourceBundle rb = ResourceBundle.getBundle(name);
    	final Map<String, String> map = new HashMap<String, String>();
    	
        for (Enumeration<String> keys = rb.getKeys (); keys.hasMoreElements ();)
        {
            final String key = keys.nextElement ();
            final String value = rb.getString (key);
         
            map.put (key, value);
        } 
    	
    	return map;
    }
}
